package com.zhouk.ams.environment;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
 * Create By Zhouke on 2017/12/07
 */
@Configuration
public class LocalEnvironment implements EnvironmentAware{
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Value("${spring.datasource.url}") // 使用el表达式读取spring主配置文件
    private String jdbcUrl;

    @Override
    public void setEnvironment(Environment environment) {
        // springEL表达式获取的值
        logger.info("springel表达式获取的值：" + jdbcUrl);

        // 获取系统属性：
        logger.info("JAVA_HOME" + environment.getProperty("JAVA_HOME"));

        // 获取spring主配置文件中的属性
        logger.info("spring.datasource.url:" + environment.getProperty("spring.datasource.url"));

        // 获取前缀是“spring.datasource”的所有属性值
        //RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(environment, "spring.datasource.");
        //logger.info("通过前缀获取的url:" + propertyResolver.getProperty("url"));
        //logger.info("通过前缀获取的driverClassName:" + propertyResolver.getProperty("driverClassName"));

    }
}
